/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef __CARDPOCKETWIDGET_H__
#define __CARDPOCKETWIDGET_H__

#include "gametypes.h"
#include "clienttypes.h"

#include <QFrame>
#include <QPoint>

namespace client
{
    class GameActionMgr;
    class CardWidget;

    /**
     * The CardPocketWidget class is the base class of all widgets that can hold
     * cards (CardWidget instances). This class manages common properties of card
     * pockets and defines a common interface.
     * @author MacJariel
     */
    class CardPocketWidget: public QFrame
    {
        Q_OBJECT;
    public:
        /// Constructs a CardPocketWidget and sets its isRevealed property.
        CardPocketWidget(QWidget *parent, bool isRevealed);

        /// Destroys the CardPocketWidget.
        virtual ~CardPocketWidget();

        /// Returns whether this pocket can contain revealed cards.
        bool isRevealed() const;

        /// Returns the owner's id.
        PlayerId ownerId() const;

        PocketType pocketType() const;

        /// Returns the position (relative to this widget) of the next card to be
        /// added to pocket. This is used for card movements between pockets.
        virtual QPoint newCardPosition() const = 0;

        /// Updates the pocketType and ownerId properties of pushed card widget.
        virtual void push(CardWidget*);

        /// Removes all cards from the pocket.
        virtual void clear() = 0;

        /// Sets whether this pocket can contain revealed cards. If set to false,
        /// cards that are pushed into this pocket are automatically unrevealed.
        /// @note The unrevealing is implemented in CardMovementCmd
        void setRevealed(bool isRevealed);

        /// Sets the PocketType to given type.
        void setPocketType(const PocketType&);

        /// Sets the owner of the pocket. Pockets without owner should be set to 0.
        void setOwnerId(PlayerId);

        /// Sets the CardSizeRole of the pocket. This role is used on all CardWidget
        /// that this instance contains.
        void setCardSizeRole(CardSizeRole);

        /// Sets the pointer to GameActionMgr. This is necessary for card pockets
        /// that create new Card Widgets.
        virtual void setGameActionMgr(GameActionMgr* gameActionMgr);

    public slots:
        /// Recomputes size of the widget and reorders CardWidgets. The actual CardWidget size
        /// from CardWidgetSizeManager is used.
        virtual void updateSize();

    signals:
        /// This signal is emitted when CardPocketWidget's newCardPosition() changes.
        /// @todo make sure it's properly implemented
        void newCardPositionChanged(const QPoint&);

    protected:
        bool            m_isRevealed;
        PocketType      m_pocketType;
        PlayerId        m_ownerId;
        CardSizeRole    m_cardSizeRole;
        GameActionMgr*  mp_gameActionMgr;
    };

    inline bool CardPocketWidget::isRevealed() const
    {
        return m_isRevealed;
    }

    inline PocketType CardPocketWidget::pocketType() const
    {
        return m_pocketType;
    }

    inline PlayerId CardPocketWidget::ownerId() const
    {
        return m_ownerId;
    }

    inline void CardPocketWidget::setRevealed(bool isRevealed)
    {
        m_isRevealed = isRevealed;
    }

    inline void CardPocketWidget::setPocketType(const PocketType& pocketType)
    {
        m_pocketType = pocketType;
    }

    inline void CardPocketWidget::setOwnerId(PlayerId playerId)
    {
        m_ownerId = playerId;
    }

    inline void CardPocketWidget::setCardSizeRole(CardSizeRole cardSizeRole)
    {
        m_cardSizeRole = cardSizeRole;
    }

    inline void CardPocketWidget::setGameActionMgr(GameActionMgr* gameActionMgr)
    {
        mp_gameActionMgr = gameActionMgr;
    }
}
#endif // __CARDPOCKETWIDGET_H__
